package cn.texous.demo.dnw.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * Created by Alexey Malyshev on 25.06.2018
 */
@Configuration
public class SwaggerConfig {

    private static final String ROOT_CONTROLLER = "com.superads.apigateway.web.controller";
    private static final String URI_APACHE = "https://www.apache.org/licenses/LICENSE-2.0";

    @Value("${superads.config.swagger.server.title}")
    private String title;
    @Value("${superads.config.swagger.server.version}")
    private String version;

    /***/
    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.basePackage(ROOT_CONTROLLER))
                .paths(PathSelectors.any())
                .build()
                .apiInfo(apiInfo(title, version));
    }

    private ApiInfo apiInfo(String title, String version) {
        return new ApiInfoBuilder()
                .title("REST API " + title)
                .version("Version " + version)
                .license("Apache License Version 2.0")
                .licenseUrl(URI_APACHE)
                .build();
    }

}
